package u.can.i.up.gearmanimpl;

import java.io.IOException;

import org.gearman.Gearman;

import u.can.i.up.gearmanimpl.common.Configuration;
import u.can.i.up.gearmanimpl.common.Constants;

/**
 * The echo worker/server starts a new server and polls jobs from it job server
 * 
 * The echo worker illustrates how to setup a basic worker
 */
public class JobServer {
	
	public static final int SERVER_PORT = Configuration.getInt(Constants.SERVERPORT, 4730);
	
	public static void main(String... args) throws IOException {
		/*
		 * Create a Gearman instance
		 */
		Gearman gearman = Gearman.createGearman();
		try {
			/*
			 * Start a new job server. The resulting server will be running in
			 * the local address space.
			 * 
			 * Parameter 1: The port number to listen on
			 * 
			 * throws IOException
			 */
			gearman.startGearmanServer(SERVER_PORT);
		} catch (IOException ioe) {

			/*
			 * If an exception occurs, make sure the gearman service is shutdown
			 */
			gearman.shutdown();

			// forward exception
			throw ioe;
		}
	}
}